<?php
  class osc_categories {
    var $code = 'bm_categories';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;
	var $filename = '';

    function osc_categories() {
      global $wholesaler, $PHP_SELF;
	  
	  $this->title = 'CATEGORIES';

	  switch(basename($PHP_SELF)) {
		case FILENAME_DEFAULT;
		  $this->filename = FILENAME_DEFAULT;
		  break;
		case FILENAME_WHOLESALE;
		  $this->filename = FILENAME_WHOLESALE;
		  break;
		default;
		  $this->filename = FILENAME_DEFAULT;
		  if (tep_session_is_registered('customer_id')) {
			if($wholesaler == 1) {
			  $this->filename = FILENAME_WHOLESALE;
			}
		  }
		  break;
	  }
    }

    function tep_show_category($counter) {
      global $tree, $categories_string, $cPath_array;

	  $classname = 'lvl-' . $tree[$counter]['level'];
	  
      if ($tree[$counter]['parent'] == 0) {
        $cPath_new = 'cPath=' . $counter;
      } else {
        $cPath_new = 'cPath=' . $tree[$counter]['path'];
      }
	   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
		   $categories_string .= '<li class="' . $classname . ' actived"><a href="';
      } else {
		  $categories_string .= '<li class="' . $classname . '"><a href="';
	  }
      
      $categories_string .= tep_href_link($this->filename, $cPath_new) . '"><span></span>';

	  // display category name
      $categories_string .= $tree[$counter]['name'];
      $categories_string .= '</a></li>';

      if ($tree[$counter]['next_id'] != false) {
        $this->tep_show_category($tree[$counter]['next_id']);
      }
	  
	  $categories_string .= '';
    }

    function getData() {
      global $categories_string, $tree, $languages_id, $cPath, $cPath_array;

      $categories_string = '';
      $tree = array();

      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
      while ($categories = tep_db_fetch_array($categories_query))  {
        $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                    'parent' => $categories['parent_id'],
                                                    'level' => 0,
                                                    'path' => $categories['categories_id'],
                                                    'next_id' => false);

        if (isset($parent_id)) {
          $tree[$parent_id]['next_id'] = $categories['categories_id'];
        }

        $parent_id = $categories['categories_id'];

        if (!isset($first_element)) {
          $first_element = $categories['categories_id'];
        }
      }

      if (tep_not_null($cPath) && $cPath != 0) {
        $new_path = '';
        reset($cPath_array);
        while (list($key, $value) = each($cPath_array)) {
          unset($parent_id);
          unset($first_id);
          $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
          if (tep_db_num_rows($categories_query) > 0) {
            $new_path .= $value;
            while ($row = tep_db_fetch_array($categories_query)) {
              $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                                   'parent' => $row['parent_id'],
                                                   'level' => $key+1,
                                                   'path' => $new_path . '_' . $row['categories_id'],
                                                   'next_id' => false);

              if (isset($parent_id)) {
                $tree[$parent_id]['next_id'] = $row['categories_id'];
              }

              $parent_id = $row['categories_id'];

              if (!isset($first_id)) {
                $first_id = $row['categories_id'];
              }

              $last_id = $row['categories_id'];
            }
            $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
            $tree[$value]['next_id'] = $first_id;
            $new_path .= '_';
          } else {
            break;
          }
        }
      }

      $this->tep_show_category($first_element);

	  $data = '
<div id="right" style="width:255px; float:right; overflow:hidden;">	  
	<div class="moduletable">
        <div id="cate_product">
		  <h1 style="border-bottom:none;">• ' . $this->title . '</h1>
		  <div class="right_list_box">
           	<div class="bottom_bg">
			  <ul class="category">' . $categories_string . '</ul>
			</div>
		  </div>';

      return $data;
    }
  }
  
$myCategories = new osc_categories();
echo $myCategories->getData();
?>

    
    <div class="moduletable_melanting">
		<h1 style="text-align: left;">CONTACT</h1>
		<div style="text-align: left;" id="contact_melanting">Tel:&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; +32 (0)56 293 837 <br>
            Mob: &nbsp;&nbsp;&nbsp; &nbsp;+32 (0)484 227 741 <br>
            Email: &nbsp;&nbsp; &nbsp;<a href="http://melanting.be/">contact@melanting.be</a>
        </div>
	</div>
</div></div></div>